///////////////////////////////////////////////////////////////////////////////////
// 弹窗调用接口封装
//开发人：虞胜强
//开发时间：2019/3/25
///////////////////////////////////////////////////////////////////////////////////
layui.define(['jquery', 'layer','validUtil'], function (exports) {
    var $ = layui.jquery,
        validUtil = layui.validUtil;
    var layer = parent.layer === undefined ? layui.layer : top.layer;
    var dialog = {
        /***
         * 询问框方法
         * @param message 内容
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        confirm: function (message,successFn,cancelFn) {
            dialog.confirmTitleMessage("信息",message,successFn,cancelFn);
        },
        /***
         * 询问框方法
         * @param title 标题
         * @param message 内容
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        confirmTitleMessage: function (title,message,successFn,cancelFn) {
            dialog.confirmBase(title,message,['确定', '取消'],successFn,cancelFn);
        },
        /***
         * 询问框方法
         * @param message 内容
         * @param btn 按钮
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        confirmMessageBtn: function (message,btn,successFn,cancelFn) {
            dialog.confirmBase("信息",message,btn,successFn,cancelFn);
        },
        /***
         * 询问框方法
         * @param title 标题
         * @param message 内容
         * @param btn 按钮
         * @param successFn 点击‘确定’回调方法
         * @param cancelFn 点击‘取消’回调方法
         */
        confirmBase: function (title,message,btn,successFn,cancelFn) {
            layer.confirm(message, {
                title:title,
                btn: btn,
                shade: [0.1, '#fff']
            }, function (index) {
                layer.close(index);
                if(typeof successFn=='function'){
                    successFn();
                }
            }, function (index) {
                layer.close(index);
                if(typeof cancelFn=='function'){
                    cancelFn();
                }
            });
        },
        /**
         * 提示框
         *
         * @param msg 提示内容
         * @author shengQiang yu
         * @date 2019-03-05 15:40
         */
        msg: function (msg) {
            layer.msg(msg, {time: 1 * 1000});
        },
        /**
         * 弹窗页面
         *
         * @param title 标题
         * @param url 连接
         * @param width 弹窗宽
         * @param height 弹窗高
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpPage: function (title, url, width, height,successFn) {
            if (validUtil.isEmpty(title)) {
                title = false;
            };
            if (validUtil.isEmpty(url)) {
                url = "404.html";
            };
            if (validUtil.isEmpty(width)) {
                width = '700px';
            };
            if (validUtil.isEmpty(height)) {
                height = '620px';
            };
            var index = layer.open({
                type: 2,
                title: title,
                area: [width, height],
                fixed: false, //不固定
                maxmin: true,
                content: url,
                success: function (layero, index) {
                    if(typeof successFn=='function'){
                        successFn(layer, index);
                    }
                }
            });
        },
        /**
         * 基础单选选择器弹窗页面
         *
         * @param title 标题
         * @param url 连接
         * @param successFn 成功回调
         * @param width 弹窗宽
         * @param height 弹窗高
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpSingleSelect: function (title, url,successFn, width, height) {
            if (validUtil.isEmpty(title)) {
                title = "选择器";
            }
            if (validUtil.isEmpty(width)) {
                width = 380;
            }
            if (validUtil.isEmpty(height)) {
                height = 560;
            }
            dialog.popUpPage(title,"/base/selector/single?url=" + url,width+'px',height+'px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    var id = body.find("#resultId").val();
                    var name = body.find("#resultName").val();
                    if(typeof successFn=='function'){
                        successFn(id,name,layer,index);
                    }
                    parent.layer.close(index);
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        },
        /**
         * 基础多选选择器弹窗页面
         *
         * @param title 标题
         * @param url 连接
         * @param successFn 成功回调
         * @param initIds 初始化选中对象id集合，多个用“,”隔开
         * @param width 弹窗宽
         * @param height 弹窗高
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpMultSelect: function (title, url,successFn,initIds,width, height) {
            //初始化选中对象id集合
            var params = [];
            params.push(initIds);
            //初始化id值
            parent.cytSetSelectObjctParams(params);

            if (validUtil.isEmpty(title)) {
                title = "选择器";
            }
            if (validUtil.isEmpty(width)) {
                width = 380;
            }
            if (validUtil.isEmpty(height)) {
                height = 560;
            }
            dialog.popUpPage(title,"/base/selector/mult?url=" + url,width+'px',height+'px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    var id = body.find("#resultId").val();
                    var name = body.find("#resultName").val();
                    if(typeof successFn=='function'){
                        successFn(id,name,layer,index);
                    }
                    parent.layer.close(index);
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        },
        /**
         * 学校应用多选选择器弹窗页面(仿e智云）
         *
         * @param ids 展示id值的id
         * @param title 弹窗标题
         * @param names 展示name值的id
         * @param initIds 选中值id显示位置
         * @param successFn 成功回调
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpSchoolApplyMultSelect: function (ids,names,title,initIds,successFn){
            if(validUtil.isEmpty(title)){
                title="学校选择"
            }
            dialog.popUpBaseCytMultSelectNoTree(initIds,title,"学校,应用","请输入内容","/wx/wxeducationuser/getAllTeacherList",function (idValues,nameValues) {
                if(validUtil.isNotEmpty(ids)){
                    $("#" + ids).val(idValues);
                    $("#" + ids).html(idValues);
                }
                if(validUtil.isNotEmpty(names)){
                    $("#" + names).val(nameValues);
                    $("#" + names).html(nameValues);
                    $("#" + names).attr("title", nameValues);
                }
                if (typeof successFn == 'function') {
                    successFn(idValues,nameValues);
                }
            });
        },



        /**
         * 监巡考老师选择器
         *
         * @param ids 展示id值的id
         * @param title 弹窗标题
         * @param names 展示name值的id
         * @param initIds 选中值id显示位置
         * @param successFn 成功回调
         * @author hanjun
         * @date 2019-09-26
         */
        popUpNewTeacherApplyMultSelect: function (type,ksId,ids,names,title,initIds,successFn){
            debugger;
            if(validUtil.isEmpty(title)){
                title="学校选择"
            }
            dialog.popUpBaseCytMultSelectNoTree(initIds,title,"姓名,工号","请输入内容","/work/kwmanagement/kwteachersetting/getAllTeacherListjxk?type="+type+"&ksId="+ksId,function (idValues,nameValues) {
                if(validUtil.isNotEmpty(ids)){
                    $("#" + ids).val(idValues);
                    $("#" + ids).html(idValues);
                }
                if(validUtil.isNotEmpty(names)){
                    $("#" + names).val(nameValues);
                    $("#" + names).html(nameValues);
                    $("#" + names).attr("title", nameValues);
                }
                if (typeof successFn == 'function') {
                    successFn(idValues,nameValues);
                }
            });
        },




        /**
         * 教师多选取
         *
         * @param ids 展示id值的id
         * @param title 弹窗标题
         * @param names 展示name值的id
         * @param initIds 选中值id显示位置
         * @param successFn 成功回调
         * @author hanjun
         * @date 2019-09-26
         */
        popUpScTeacherApplyMultSelect: function (ids,names,applyId,title,initIds,successFn){
            debugger;
            if(validUtil.isEmpty(title)){
                title="学校选择"
            }
            dialog.popUpBaseCytMultSelectNoTree(initIds,title,"姓名,工号","请输入内容","/wx/wxeducationuser/getAllTeacherList?applyId="+applyId,function (idValues,nameValues) {
                if(validUtil.isNotEmpty(ids)){
                    $("#" + ids).val(idValues);
                    $("#" + ids).html(idValues);
                }
                if(validUtil.isNotEmpty(names)){
                    $("#" + names).val(nameValues);
                    $("#" + names).html(nameValues);
                    $("#" + names).attr("title", nameValues);
                }
                if (typeof successFn == 'function') {
                    successFn(idValues,nameValues);
                }
            });
        },


        /**
         * 座位选择器
         *
         * @param ids 展示id值的id
         * @param title 弹窗标题
         * @param names 展示name值的id
         * @param initIds 选中值id显示位置
         * @param successFn 成功回调
         * @author hanjun
         * @date 2019-09-26
         */
        popUpSeatNumApplyMultSelect: function (ksId,kcId,ids,names,title,initIds,successFn){
            if(validUtil.isEmpty(title)){
                title="座位选择"
            }
            dialog.popUpBaseCytMultSelectNoTree(initIds,title,"考场,座位","请输入内容","/work/kwmanagement/kwteachersetting/getAllStudentSeatNum?ksId="+ksId+"&kcId="+kcId,function (idValues,nameValues) {
                if(validUtil.isNotEmpty(ids)){
                    $("#" + ids).val(idValues);
                    $("#" + ids).html(idValues);
                }
                if(validUtil.isNotEmpty(names)){
                    $("#" + names).val(nameValues);
                    $("#" + names).html(nameValues);
                    $("#" + names).attr("title", nameValues);
                }
                if (typeof successFn == 'function') {
                    if(idValues.indexOf(",")>0){
                        dialog.msg("请选择单个座位");
                    }else {
                        successFn(idValues,nameValues);
                    }

                }
            });
        },



        /**
         * 科目多选择器
         *
         * @param ids 展示id值的id
         * @param title 弹窗标题
         * @param names 展示name值的id
         * @param initIds 选中值id显示位置
         * @param successFn 成功回调
         * @author hanjun
         * @date 2019-09-26
         */
        popUpScSubjectApplyMultSelect: function (ids,names,title,initIds,successFn){
            if(validUtil.isEmpty(title)){
                title="科目选择"
            }
            debugger;
            dialog.popUpBaseCytMultSelectNoTree(initIds,title,"名称,代码值","请输入科目名称","/sysDict/AllSublist",function (idValues,nameValues) {
                if(validUtil.isNotEmpty(ids)){
                    $("#" + ids).val(idValues);
                    $("#" + ids).html(idValues);
                }
                if(validUtil.isNotEmpty(names)){
                    $("#" + names).val(nameValues);
                    $("#" + names).html(nameValues);
                    $("#" + names).attr("title", nameValues);
                }
                if (typeof cytSelectMoreCourseCallBack == 'function') {
                    cytSelectMoreCourseCallBack(nameValues);
                }
                debugger;

                if (typeof successFn == 'function') {
                    successFn(idValues,nameValues);
                }
            });
        },






        /**
         * 用户多选选择器弹窗页面(仿e智云）
         *
         * @param ids 展示id值的id
         * @param title 弹窗标题
         * @param names 展示name值的id
         * @param initIds 选中值id显示位置
         * @param successFn 成功回调
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpUserMultSelect: function (ids,names,title,initIds,successFn){
            if(validUtil.isEmpty(title)){
                title="用户选择"
            }
            dialog.popUpBaseCytMultSelect(initIds,title,"姓名,部门","请输入内容","/sysOrganization/dTreeList","/sysOrgUser/selector",function (idValues,nameValues) {
                if(validUtil.isNotEmpty(ids)){
                    $("#" + ids).val(idValues);
                    $("#" + ids).html(idValues);
                }
                if(validUtil.isNotEmpty(names)){
                    $("#" + names).val(nameValues);
                    $("#" + names).html(nameValues);
                    $("#" + names).attr("title", nameValues);
                }
                if (typeof successFn == 'function') {
                    successFn(idValues,nameValues);
                }
            });
        },
        /**
         * 基础多选选择器弹窗页面(仿e智云）
         *
         * @param initIds 选中值id显示位置
         * @param title 弹窗标题
         * @param selectTitle 展示选项名称，多个以“，”隔开
         * @param seacherTip 搜索提示
         * @param treeUrl 左边树数据url接口
         * @param dataUrl 中间数据url接口
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpBaseCytMultSelect: function (initIds,title,selectTitle,seacherTip, treeUrl, dataUrl,successFn) {
            //初始化选中对象id集合
            var params = [];
            params.push(initIds);//初始化选中对象id集合
            params.push(selectTitle);//标题名称
            params.push(seacherTip);//搜索提示
            params.push(treeUrl);//左边树url接口
            params.push(dataUrl);//中间数据url接口
            //初始化id值
            parent.cytSetSelectObjctParams(params);
            if (validUtil.isEmpty(title)) {
                title = "选择器";
            }
            dialog.popUpPage(title,"/base/selector/cytMult",'900px','630px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    var idValues = null;
                    var nameValues = null;
                    body.find("#showTableRight tr").each(function (i, e) {
                        var id = $(e).find("input[name='id']").val();
                        var name = $(e).find("input[name='name']").val();
                        var number = $(e).find("input[name='number']").val();
                        if (idValues == null || idValues == "") {
                            idValues = id;
                        } else {
                            idValues += "," + id;
                        }
                        if (nameValues == null || nameValues == "") {
                            nameValues = name;
                        } else {
                            nameValues += "," + name;
                        }

                    });
                    if(typeof successFn=='function'){
                        successFn(idValues,nameValues,layer,index);
                    }
                    parent.layer.close(index);
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        },
        /**
         * 基础多选选择器无左边树弹窗页面(仿e智云）
         *
         * @param initIds 选中值id显示位置
         * @param title 弹窗标题
         * @param selectTitle 展示选项名称，多个以“，”隔开
         * @param seacherTip 搜索提示
         * @param treeUrl 左边树数据url接口
         * @param dataUrl 中间数据url接口
         * @author shengQiang yu
         * @date 2019-03-11 9:44
         */
        popUpBaseCytMultSelectNoTree: function (initIds,title,selectTitle,seacherTip, dataUrl,successFn) {
            //初始化选中对象id集合
            var params = [];
            debugger;
            params.push(initIds);//初始化选中对象id集合
            params.push(selectTitle);//标题名称
            params.push(seacherTip);//搜索提示
            params.push(dataUrl);//中间数据url接口
            //初始化id值
            parent.cytSetSelectObjctParams(params);
            if (validUtil.isEmpty(title)) {
                title = "选择器";
            }
            dialog.popUpPage(title,"/base/selector/cytMultSelectorNoTree",'660px','609px', function (layer, index) {
                var body = layer.getChildFrame('body', index);
                body.find("#save").bind("click", function () {
                    var idValues = null;
                    var nameValues = null;
                    body.find("#showTableRight tr").each(function (i, e) {
                        var obj = {};
                        var id = $(e).find("input[name='id']").val();
                        var name = $(e).find("input[name='name']").val();
                        if (idValues == null || idValues == "") {
                            idValues = id;
                        } else {
                            idValues += "," + id;
                        }
                        if (nameValues == null || nameValues == "") {
                            nameValues = name;
                        } else {
                            nameValues += "," + name;
                        }
                    });
                    if(typeof successFn=='function'){
                        successFn(idValues,nameValues,layer,index);
                    }
                    parent.layer.close(index);
                });
                body.find("#cancel").bind("click", function () {
                    parent.layer.close(index);
                });
            });
        },
        /**
         * 提示
         * @param title
         * @param obj
         */
        tips: function (title, obj) {
            layer.tips(title, obj, {
                tips: [1, '#444c63'], //还可配置颜色
                time: 1000
            });
        }
    };
    //输出test接口
    exports('dialog', dialog);
});
